import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";

const routes: Array<RouteRecordRaw> = [];

// 动态导入路由
const modules: Record<string, any> = import.meta.glob(["./module/*.ts"], {
  eager: true,
});

Object.keys(modules).forEach((key) => {
  const module = modules[key].default;
  routes.push(module);
});

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

router.beforeEach(async (_to, _from, next) => {
  NProgress.start();
  next();
});

router.afterEach((_to) => {
  NProgress.done();
});

export default router;
